<template>
  <svg :class="svgClass"
       aria-hidden="true"
       :style="svgStyle">
    <use :xlink:href="iconName" />
  </svg>
</template>

<script>
export default {
  name: 'SvgIcon',
  props: {
    iconClass: {
      type: String,
      required: true
    },
    className: {
      type: String,
      default: ''
    },
    size: {
      type: String,
      default: ''
    },
    color: {
      type: String,
      default: ''
    }
  },
  computed: {
    iconName () {
      return `#icon-${this.iconClass}`;
    },
    svgClass () {
      if (this.className) {
        return 'svg-icon ' + this.className;
      } else {
        return 'svg-icon';
      }
    },
    svgStyle () {
      const style = {};
      if (this.size) {
        style['font-size'] = this.size;
      }
      if (this.color) {
        style['color'] = this.color;
      }
      return style;
    }
  }
};
</script>
